﻿using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;

public class TwoMaskNode : TutorialNode
{
    public enum MaskType
    {
        UI,
        Rect,
    }

    [JsonAttribute("fmask", "第一个Mask的类型")]
    public MaskType firstMaskType;

    [JsonAttribute("f_uiPath", "第一个(UI路径)", "", "UIprefab对象, 子节点路径")]
    public List<string> first_uiPath = new List<string>() { "", "" };

    [JsonAttribute("f_aridx", "第一个矩形(屏幕比例)")]
    public Rect f_areaIndex = new Rect();

    [JsonAttribute("smask", "第二个Mask的类型")]
    public MaskType secondMaskType;

    [JsonAttribute("s_uiPath", "第二个(UI路径)", "", "UIprefab对象, 子节点路径")]
    public List<string> second_uiPath = new List<string>() { "", "" };

    [JsonAttribute("s_aridx", "第二个矩形(屏幕比例)")]
    public Rect s_areaIndex = new Rect();

    [JsonAttribute("alpha", "遮罩透明度")]
    public float alpha = 0.3f;

#if UNITY_EDITOR
    [JsonEditorAttribute(typeof(UIPathSwitchMember), "f_uiPath")]
    public List<object> f_uiPath = new List<object>();
#endif

#if UNITY_EDITOR 
    [JsonEditorAttribute(typeof(UIPathSwitchMember), "s_uiPath")]
    public List<object> s_uiPath = new List<object>();
#endif

    protected override void Init()
    {
        AddTutorialComponent(new UIOperitionComponent());
        _tutorialManager.StartCoroutine(RealyInit());
       
    }

    protected IEnumerator RealyInit()
    {
        yield return new WaitForEndOfFrame();
        Canvas canvas = Hope.UIManager.Instance.UIRoot.GetComponent<Canvas>();
        Rect a = Rect.zero, b = Rect.zero;
        switch (firstMaskType)
        {
            case MaskType.UI:
                var node = TutorialLogicUtils.GetTransfromByUIPath(Hope.UIManager.Instance.UIRoot, first_uiPath);
                a = TutorialUIManager.Instance.GetRect(node as RectTransform, canvas);
                break;
            case MaskType.Rect:
                break;
            default:
                break;
        }

        switch (secondMaskType)
        {
            case MaskType.UI:
                var node = TutorialLogicUtils.GetTransfromByUIPath(Hope.UIManager.Instance.UIRoot, second_uiPath);
                b = TutorialUIManager.Instance.GetRect(node as RectTransform, canvas);
                break;
            case MaskType.Rect:
                break;
            default:
                break;
        }
        TutorialUIManager.Instance.ShowTwoMask(a, b, canvas, alpha);

    }

    protected override void Cancel()
    {
        TutorialUIManager.Instance.HideTwoMask();
    }
}

